<template>
  <div>
    <svg-icon
      :icon-class="isFull ? 'exit-fullscreen' : 'fullscreen'"
      class="fullscreen"
      @click="dianji"
    />
  </div>
</template>

<script>
import screenfull from 'screenfull'
export default {
  name: 'ScreenFull',
  data () {
    return {
      isFull: false
    }
  },
  created () {
    if (screenfull.isEnabled) {
      screenfull.on('change', () => {
        if (screenfull.isFullscreen) {
          this.isFull = true
        } else {
          this.isFull = false
        }
      })
    }
  },
  beforeDestroy () {
    screenfull.off('change')
  },
  methods: {
    dianji () {
      if (!screenfull.isEnabled) {
        return this.$message.success('你的浏览器不支持!')
      }
      screenfull.toggle()
    }
  }

}
</script>

<style lang="scss" scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  color: #fff;
  cursor: pointer;
}
</style>
